package com.mytrip.webapp.session;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import com.mytrip.model.BackOperator;
import com.mytrip.model.RoleModule;
import com.mytrip.model.Userinfo;

/**
 * SessionBagImpl
 */
public class SessionBagImpl implements SessionBag{
	private static final long serialVersionUID = 8365719448248298139L;

	private BackOperator backOperator;
	
	private Userinfo userinfo;

	private String cookieValue;

	private String memcacheKey;

	private Map<String, String> modulePwdMap = new HashMap<String, String>();

	// d
	private Long warehouseId;

	private Map<String, Object> purchaseInfo = new HashMap<String, Object>(0);

	private Locale locale;

	// key: RoleModule.actionName
	private Map<String, RoleModule> roleModuleMap = new HashMap<String, RoleModule>(0);

	private String ip;

	private String sessionNbr;

	// 判断是否有更新，如果有，put到mc
	private boolean updated;

	public SessionBagImpl(){
		warehouseId = 1L;
	}

	public Locale getLocale(){
		return locale;
	}

	public void setLocale(Locale locale){
		this.locale = locale;
		// update();
	}

	public Long getWarehouseId(){
		return warehouseId;
	}

	public void setWarehouseId(Long warehouseId){
		this.warehouseId = warehouseId;
	}

	public Map<String, Object> getPurchaseInfo(){
		update();
		return purchaseInfo;
	}

	public void setPurchaseInfo(Map<String, Object> purchaseInfo){
		this.purchaseInfo = purchaseInfo;
		update();
	}

	public Map<String, RoleModule> getRoleModuleMap(){
		return this.roleModuleMap;
	}

	public void setRoleModuleMap(Map<String, RoleModule> roleModuleMap){
		this.roleModuleMap = roleModuleMap;
		update();
	}

	public String getIp(){
		return ip;
	}

	public void setIp(String ip){
		this.ip = ip;
		// update();
	}

	public String getSessionNbr(){
		return sessionNbr;
	}

	public void setSessionNbr(String sessionNbr){
		this.sessionNbr = sessionNbr;
		// update();
	}

	public BackOperator getBackOperator(){
		return backOperator;
	}

	public void setBackOperator(BackOperator backOperator){
		this.backOperator = backOperator;
		update();
	}

	public Map<String, String> getModulePwdMap(){
		return modulePwdMap;
	}

	public void setModulePwdMap(Map<String, String> modulePwdMap){
		this.modulePwdMap = modulePwdMap;
		update();
	}

	public String getCookieValue(){
		return cookieValue;
	}

	public void setCookieValue(String cookieValue){
		this.cookieValue = cookieValue;
		update();
	}

	public String getMemcacheKey(){
		return memcacheKey;
	}

	public void setMemcacheKey(String memcacheKey){
		this.memcacheKey = memcacheKey;
		update();
	}

	public void update(){
		this.updated = true;
	}

	public void freshUpdate(){
		this.updated = false;
	}

	public boolean isUpdated(){
		return updated;
	}

	public Userinfo getUserinfo(){
		return userinfo;
	}

	public void setUserinfo(Userinfo userinfo){
		this.userinfo = userinfo;
	}

}
